package com.jsgt.greekfire.ui.news

import android.view.ViewGroup
import android.webkit.WebResourceRequest
import android.webkit.WebView
import com.fhx.core.base.BaseFragment
import com.fhx.core.utils.ToastUtils
import com.jsgt.greekfire.R
import com.just.agentweb.AgentWeb
import com.just.agentweb.WebChromeClient
import com.just.agentweb.WebViewClient
import kotlinx.android.synthetic.main.fragment_news.*


class NewsFragment : BaseFragment() {
    var mAgentWeb: AgentWeb? = null
    var web: WebView? = null

    override fun getLayoutId(): Int {
        return R.layout.fragment_news
    }

    override fun main() {
        refresh_layout.setOnRefreshListener {
            web?.loadUrl("http://47.103.98.11:9096/#/")
        }

        mAgentWeb = AgentWeb.with(this)
            .setAgentWebParent(container, ViewGroup.LayoutParams(-1, -1))
            .useDefaultIndicator()
            .setWebViewClient(object : WebViewClient() {
                override fun onPageFinished(view: WebView?, url: String?) {
                    super.onPageFinished(view, url)
                    refresh_layout.isRefreshing = false
                }
            })
            .createAgentWeb()
            .ready()
            .go("http://47.103.98.11:9096/#/")
        web = mAgentWeb?.webCreator?.webView
    }

    override fun onPause() {
        mAgentWeb!!.webLifeCycle.onPause()
        super.onPause()
    }

    override fun onResume() {
        mAgentWeb!!.webLifeCycle.onResume()
        super.onResume()
    }

    override fun onDestroyView() {
        mAgentWeb!!.webLifeCycle.onDestroy()
        super.onDestroyView()
    }
}